import type { VNode } from 'vue';
import type { FormItemSchema } from '../schema-form/types/form';
import type { ActionItem } from './types/tableAction';
import type { TableProps as SuperTableProps } from './props';
import { VxeTableDefines } from "vxe-table/types/table";
import type { PermissionType } from '@/framework/core/permission/modules/types';
/**
 * 加载表格数据的参数
 */
export interface LoadDataParams {
  /** 根据自己业务需求定义页码 */
  page?: number;
  /** 根据自己业务需求定义页数据条数 */
  limit?: number;
}

export type ColumnParams<T = any> = {
  row: T;
  rowIndex: number;
  $rowIndex: number;
  column: VxeTableDefines.ColumnOptions;
  columnIndex: number;
  $columnIndex: number;
  _columnIndex: number;
};

/** 表格onChange事件回调参数 */
// export type OnChangeCallbackParams = VxeTableProps['onChange'];

/**
 * 表格属性
 */
export interface TableColumn<T = Indexable> extends Omit<VxeTableDefines.ColumnOptions, 'field' > {
  title: string;
  field?: keyof T | '$action';
  width?: number;
  /** 指定搜索的字段 */
  searchField?: string;
  /** 在查询表单中不展示此项 */
  hideInSearch?: boolean;
  /** 在 Table 中不展示此列 */
  hideInTable?: boolean;
  /** 传递给 Form.Item 的配置,可以配置 rules */
  formItemProps?: Partial<FormItemSchema<T>>;
  bodyCell?: (params: ColumnParams<T>) => VNode;
  headerCell?: (params: ColumnParams<T>) => VNode;
  actions?: (params: ColumnParams<T>) => ActionItem[];
  /** 字典映射字段 */
  dict?: string;
  /** 自定义字段插槽*/
  slots?: any;
  /** 当前列所需权限 */
  perm?: PermissionType
}

/**
 * 表格实例
 */
export type SuperTableInstance = {
  [P in keyof SuperTableProps]: SuperTableProps[P];
} & {
  tableData: any[];
  setProps(props: Partial<SuperTableProps>): () => any;
  getProps: SuperTableProps;
  refreshTable: (...rest: any[]) => any;
  getColumnKey: (column: TableColumn) => string | undefined;
};
